<template>
  <div>
    <!-- 页面基础模板 -->
    <base-header-footer
      :isShowContentTitle="false"
      :isShowBreadCrumb="false"
      :isShowArchived="true"
    >
      <!-- isShowTitle : 布尔值，是否显示当前页面标题组件-->
      <!-- isShowBreadCrumb : 布尔值，是否显示当前页面面包屑导航组件-->
      <!-- isShowArchived : 布尔值，是否显示当前页面归档组件-->
      <template slot="content-item-breadCrumb">
        <!-- 自定义面包屑导航插槽 -->
      </template>
      <template slot="content-item">
        <!-- 内容插槽 -->
        <div class="personal">
          <div class="personal-bg">
            <img
              :src="
                OtherUserInfo?.bgCover || require('@/static/personal-bg.jpg')
              "
              alt=""
            />
          </div>
          <div class="personal-content">
            <div class="upload-avatar">
              <div class="upload-content" @click="dialogVisible = true">
                <img
                  :src="
                    OtherUserInfo?.avatar || require('@/static/UserAvatar.png')
                  "
                  alt=""
                />
              </div>
              <h1>{{ OtherUserInfo?.nickname }}</h1>
              <span>{{ OtherUserInfo?.introduct }}</span>
            </div>
            <p>
              <span><span>{{articleListTotalNum}}</span>文章</span>
              <span><span>{{commentListTotalNum}}</span>评论</span>
              <span><span>0</span>粉丝</span>
            </p>
            <div>
              <button><i class="el-icon-plus"></i>关注</button>
              <button><i class="el-icon-message"></i>私信</button>
            </div>
          </div>
        </div>
        <div class="personal-tabs">
          <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
            <el-tab-pane label="文章" name="first">
              <div class="tabs-article" v-if="articleList.length == 0">
                <img src="@/static/empty-post.svg" alt="" />
                <p>你还没有发布任何文章。</p>
              </div>
              <div v-else>
                <UserArticleList :articleList="articleList"></UserArticleList>
                <div class="toLoad" v-show="isShowToLoad">
                  <p @click="handleToLoad">点击查看更多</p>
                </div>
              </div>
            </el-tab-pane>
            <el-tab-pane label="评论" name="second">
              <div class="tabs-article" v-if="commentList.length == 0">
                <img src="@/static/empty-post.svg" alt="" />
                <p>你还没有发布任何评论。</p>
              </div>
              <div v-else>
                <UserCommentList :commentList="commentList"></UserCommentList>
                <div class="toLoad" v-show="isShowToLoad">
                  <p @click="handleToLoad">点击查看更多</p>
                </div>
              </div>
            </el-tab-pane>
            <el-tab-pane label="问答" name="third">
              <div class="tabs-btn">
                <button
                  :class="activeBtnOne ? 'active' : ''"
                  @click="handleQa(true)"
                >
                  问题
                </button>
                <button
                  :class="!activeBtnOne ? 'active' : ''"
                  @click="handleQa(false)"
                >
                  回答
                </button>
              </div>
              <div class="tabs-article">
                <img src="@/static/empty-qa.svg" alt="" />
                <p>你还没有{{ activeBtnOne ? "发布" : "回答" }}任何问题。</p>
              </div>
            </el-tab-pane>
            <el-tab-pane label="关注" name="fourth">
              <div class="tabs-btn">
                <button
                  :class="activeBtnOne ? 'active' : ''"
                  @click="handleQa(true)"
                >
                  Ta关注的人
                </button>
                <button
                  :class="!activeBtnOne ? 'active' : ''"
                  @click="handleQa(false)"
                >
                  关注Ta的人
                </button>
              </div>
              <div class="tabs-article">
                <img src="@/static/empty-follow.svg" alt="" />
                <p v-show="activeBtnOne">您还没有关注任何用户。</p>
                <p v-show="!activeBtnOne">您还没有被任何粉丝关注。</p>
              </div></el-tab-pane
            >
            <el-tab-pane label="收藏" name="five">
              <div class="tabs-article" v-if="collectList.length == 0">
                <img src="@/static/empty-favorite.svg" alt="" />
                <p>你还没有收藏的文章</p>
              </div>
              <div v-else>
                <UserArticleList :articleList="collectList"></UserArticleList>
                <div class="toLoad" v-show="isShowToLoad">
                  <p @click="handleToLoad">点击查看更多</p>
                </div>
              </div>
            </el-tab-pane>
          </el-tabs>
        </div>
      </template>
    </base-header-footer>
  </div>
</template>

<script>
import UserArticleList from "@/components/otherUser/ArticleList.vue";
import UserCommentList from "@/components/otherUser/CommentList.vue";
import BaseHeaderFooter from "@/components/baseheaderfooter/BaseHeaderFooter.vue";
// import { getArticle, getOtherComment,getOtherCollect, getOtherUser } from "@/api/api";
export default {
  name: "",
  components: {
    UserArticleList,
    UserCommentList,
    BaseHeaderFooter,
  },
  data() {
    return {
      isShowToLoad: true,
      activeName: "",
      activeBtnOne: true,
      OtherUserInfo: {},
      articleList: [],
      articleListTotalNum:0,
      commentList: [],
      commentListTotalNum:0,
      collectList: [],
      totalPage: 0,
      currentPage: 1,
    };
  },
  created() {
    this.getOtherUserInfo();
    this.getArticleInfo();
    this.getCommentInfo();
    this.getCollectInfo();
    this.activeName = this.$cookies.get("activeName") || "first";
  },
  methods: {
    async getOtherUserInfo() {
      const res = await this.$api.getOtherUser({ id: this.$route.params.id });
      this.OtherUserInfo = res.data[0];
    },
    async getArticleInfo() {
      const res = await this.$api.getArticle({
        currentPage: this.currentPage,
        num: 10,
        otherUserId: this.$route.params.id,
      });
      this.articleList = [...this.articleList, ...res.data];
      this.totalPage = res.totalPage;
      this.articleListTotalNum=res.totalNum;
      if ((this.currentPage == this.totalPage && this.activeName=='first') || res.totalPage==0) {
        this.isShowToLoad = false;
      }
    },
    async getCommentInfo() {
      const res = await this.$api.getOtherComment({
        currentPage: this.currentPage,
        num: 10,
        otherUserId: this.$route.params.id,
      });
      this.commentList = [...this.commentList, ...res.data];
      this.totalPage = res.totalPage;
      this.commentListTotalNum=res.totalNum
      if ((this.currentPage == this.totalPage && this.activeName == "second") || res.totalPage==0) {
        this.isShowToLoad = false;
      }
    },
    async getCollectInfo() {
      const res = await this.$api.getOtherCollect({
        currentPage: this.currentPage,
        num: 10,
        otherUserId: this.$route.params.id,
      });
      this.collectList = [...this.collectList, ...res.data];
      this.totalPage = res.totalPage;
      if ((this.currentPage == this.totalPage && this.activeName == "five") || res.totalPage==0) {
        this.isShowToLoad = false;
      }
    },
    handleClick(tab, event) {
      this.currentPage = 1;
      this.totalPage = 0;
      this.isShowToLoad = true;
      this.articleList = [];
      this.commentList = [];
      this.collectList = [];
      if (this.activeName == "first") {
        this.getArticleInfo();
      } else if (this.activeName == "second") {
        this.getCommentInfo();
      } else if (this.activeName == "five") {
        this.getCollectInfo();
      }
      this.activeBtnOne = true;
      this.$cookies.set("activeName", this.activeName);
    },
    handleQa(value) {
      this.activeBtnOne = value;
    },
    handleToLoad() {
      this.currentPage++;
      if (this.activeName == "first") {
        this.getArticleInfo();
      } else if (this.activeName == "second") {
        this.getCommentInfo();
      } else if (this.activeName == "five") {
        this.getCollectInfo();
      }
    },
  },
};
</script>
<style lang="less" scoped>
@media only screen and (min-width: 992px) and (max-width: 1240px) {
  .personal {
    .personal-content {
      padding: 0 !important;
    }
  }
}
@media only screen and (max-width: 992px) {
  .personal {
    .personal-content {
      padding: 10px !important;
    }
  }
}
@media only screen and (max-width: 768px) {
  /deep/.content {
    margin-top: 0 !important;
  }
  .personal {
    border: 0 !important;
    .personal-bg {
      position: initial !important;
    }
    .personal-content {
      color: #000 !important;
      margin-top: -50px;
      background: #fff !important;
    }
  }
  .personal-tabs {
    border: 0 !important;
  }
}
.personal {
  border: 10px solid #f5f5f5;
  position: relative;
  .personal-bg {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: -1;
    img {
      width: 100%;
    }
  }
  .personal-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #fff;
    padding: 35px 10px;
    background: rgba(0, 0, 0, 0.3);
    p {
      margin-bottom: 20px;
      font-size: 16px;
      line-height: 1.8;
      span {
        padding: 0 8px;
        span {
          padding: 0 4px;
          font-weight: bold;
        }
      }
    }
    > div {
      button {
        color: #fff;
        margin: 0 8px;
        padding: 6px 15px;
        border-radius: 5px;
        background: #08c;
        border: 0;
        i {
          margin-right: 3px;
        }
      }
    }

    .upload-avatar {
      text-align: center;
      width: 200px;
      .upload-content {
        position: relative;
        margin: 0 auto;
        width: 76px;
        height: 76px;
        border-radius: 50%;
        border: 2px solid #fff;
        margin-bottom: 20px;
        overflow: hidden;
        img {
          width: 100%;
          height: 100%;
        }
      }
      h1 {
        font-size: 24px;
        margin-bottom: 10px;
        word-wrap: break-word;
      }
      span {
        display: block;
        font-size: 14px;
        margin-bottom: 20px;
        color: #999;
      }
    }
  }
}
.personal-tabs {
  border: 10px solid #f5f5f5;
  background: #fff;
  /deep/.el-tabs {
    .el-tabs__content {
      padding: 0 20px 20px;
      .tabs-btn {
        text-align: center;
        margin-top: 20px;
        button {
          // width: 100px;
          height: 36px;
          padding: 0 35px;
          border-radius: 0;
          outline: none;
          border: 1px solid rgb(233, 233, 233);
          cursor: pointer;
          background: #fff;
          &:hover {
            color: #fff;
            background: #3361ea;
          }
          &:nth-of-type(1) {
            border-right: 0;
            border-top-left-radius: 5px;
            border-bottom-left-radius: 5px;
          }
          &:nth-of-type(2) {
            border-left: 0;
            border-top-right-radius: 5px;
            border-bottom-right-radius: 5px;
          }
        }
        button.active {
          color: #0088cc;
          background: rgba(32, 108, 231, 0.1);
          border: 1px solid #0088cc;
          &:hover {
            color: #fff;
            background: #3361ea;
          }
        }
      }
      .tabs-article {
        text-align: center;
        padding: 60px 20px;
        img {
          margin-bottom: 20px;
        }
        p {
          color: #999;
          font-size: 14px;
        }
      }
      .toLoad {
        width: 100%;
        p {
          width: 266px;
          height: 36px;
          line-height: 36px;
          margin: 0 auto;
          font-size: 14px;
          text-align: center;
          color: #08c;
          border: 1px solid #08c;
          border-radius: 4px;
          box-sizing: border-box;
          cursor: pointer;
          &:hover {
            color: #fff;
            background: #3361ea;
            border: 1px solid #3361ea;
          }
        }
      }
    }
  }
  /deep/.el-tabs__nav-scroll {
    display: flex;
    justify-content: center;
    height: 50px;
    line-height: 50px;
    .el-tabs__item {
      padding: 0 !important;
      margin: 0 30px;
    }
    .el-tabs__item.is-active {
      color: #08c;
      border-bottom: 2px solid #0088cc !important;
    }
  }
  /deep/.el-tabs--card > .el-tabs__header .el-tabs__item {
    border: 0;
    height: 44px;
  }
  /deep/.el-tabs--card > .el-tabs__header .el-tabs__nav {
    border: 0;
  }
}
</style>
